<div class="modal-body pageContent">
        <div class="row">
            <div class="col-lg-12 col-md-12">
                
                <form action="{{url}}" enctype="multipart/form-data" method='post' id="roleForm">
                    <input name="right" type="hidden">
                    {{#if id}}
                        <input type="hidden" name="id" value="{{id}}">
                    {{/if}}
                    <div class="form-group">
                            <label class="col-lg-12 control-label"><span class="indicator">*</span><span class="indicatorName">角色名称</span></label>
                            <div class="col-lg-12">
                                <input type="text" class="form-control" name="name" value="{{name}}"/>
                            </div>
                        </div>
                        <div class="form-group">
                                <label class="col-lg-12 control-label"><span class="indicator">*</span><span class="indicatorName">菜单权限</span></label>
                                <div class="col-lg-12">
                                        <ul id="functionTree" class="ztree"></ul>
                                </div>
                            </div>
                       
                </form>
            </div>
        </div>
    </div>
    <div class="modal-footer pageFooter">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button  class="btn btn-primary"  type="submit" >保存</button>    
    </div>
    
    <script>
        var setting = {
                check: {
                    enable: true
                },
                data: {
                    simpleData: {
                        enable: true
                    }
                }
            };
        $(function(){
            console.log('{{url}}')
            // $('.selectpicker').selectpicker();//初始化
            $('#roleForm')
            .bootstrapValidator({
                message: '此值无效',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                 fields: {
                    name: {
                        message: '请输入角色名称',
                        validators: {
                            notEmpty: {
                                message: '角色名称不能为空'
                            }
                            
                        }
                    }
                }
            })
            .on('success.form.bv', function(e) {
                // Prevent form submission
                e.preventDefault();
                // Get the form instance
                var $form = $(e.target);
    
                // Get the BootstrapValidator instance
                var bv = $form.data('bootstrapValidator');
                // var treeObj = $.fn.zTree.getZTreeObj("functionTree");
                var nodes = $.fn.zTree.getZTreeObj("functionTree").getCheckedNodes(true);
                var array = new Array();
                for(var i=0; i<nodes.length;i++){
                    var id = nodes[i].id;
                    array.push(id);
                }
                var functionids = array.join(",");
                $("input[name=right]").val(functionids);
                '{{id}}' ? $('#roleListEidt').formAjax({'url':$form.attr('action'),'data':$form.serialize(),'tableRefresh':'#roleTable'}) : $('#roleListAdd').formAjax({'url':$form.attr('action'),'data':$form.serialize(),'tableRefresh':'#roleTable'})
            });
            
            getRightInfoList()
        })
        function getRightInfoList() {
            var right = '{{right}}', rightArr,treeObj, node ;
            $.ajax({
                url: '/role/getRightInfoList',
                type: 'post',
                async:false,
                success: function(json){
                    
                    $.fn.zTree.init($("#functionTree"), setting, json);
                }
            })
            if('{{right}}'){
                rightArr = right.split(',')
                treeObj = $.fn.zTree.getZTreeObj("functionTree");
                rightArr.forEach(function(value,i){
                    var node = treeObj.getNodeByParam('id',value.toString());
                    if(node){
                        treeObj.checkNode(node, true, true);
                    }
                })
            }
            
        }
    </script>